-- kill_get_item
-- created by zhuangsl
-- 击杀敌人概率获得物品奖励

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 触发
    trigger = function(who, prop, arg)
        -- 概率触发
        if DungeonM.getRandSeed("kill_get_item") % 1000 >= prop[3] then
            return;
        end

        -- 随机一种奖励
        local itemList = string.explode(prop[2], "+");
        local classId;

        if "component_1" == prop[2] then
            classId = FormulaM.invoke("FETCH_PROP_RANDOM_BONUS", prop[2]);
        elseif #itemList == 1 then
            classId = itemList[1];
        else
            classId = itemList[DungeonM.getRandSeed("kill_get_item") % #itemList + 1];
        end

        -- 目前只支持给1个
        local bonus = {1, tonumber(classId), 1};
        BonusM.doBonus(bonus, "kill_get_item");

        -- 抛出事件
        -- 抛出通用建筑奖励事件
        EventMgr.fire(event.COMM_BUILDING_BONUS, {
            ["pos"]   = arg:getPos(),
            ["type"]  = GRID_TYPE_MONSTER,
            ["bonus"] = { ["bonus"] = bonus },
            ["remainGrid"] = true,
        });
    end,

    record = function(target, prop, path)
        return false;
    end
};
